Laravel 7 pagination with search filter

123

// if $id has value it will include "where('id','<',$id) else will return all"
$wells = DB::table('well_s')
        ->when($id, function ($query, $id) {
            return $query->where('id','<',$id);
        })
        ->paginate(20);
$tests = DB::table('view_tests')->whereIn('metric_id',$metricsIds)->paginate(4);

        $tests = $tests->filter(function ($item) use ($var) {
                    return false !== stristr($item->name, $var) || 
                    false !== stristr($item->section_name, $var) || 
                    false !== stristr($item->method, $var) || 
                    false !== stristr($item->limit, $var) || 
                    false !== stristr($item->accredited_detail, $var);

               return view('frontend.test_detailes',compact('tests'))->render();
Copy code
$tests = DB::table('view_tests')
    ->whereIn('metric_id',$metricsIds)
    ->where('name', '=', $var)
    ->paginate(4);
Copy code

Comments

Submit
0 Comments